package com.zhu.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.ReferenceCountUtil;

import java.util.List;

/**
 * Created by ehsy_it on 2016-04-22.
 */
public class TimeDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        if(byteBuf.readableBytes() < 5){
            return;
        }

        list.add(byteBuf.readBytes(4));
    }

//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        ByteBuf buf = (ByteBuf)msg;
//
//        try {
//            System.out.print("------");
//            while (buf.readableBytes() > 0) {
//                System.out.print((char)buf.readByte());
//            }
//            System.out.println("------");
//        }finally{
//            ReferenceCountUtil.release(msg);
//        }
//    }
}
